package example.step3;

import example.step1.SerialPerson;

import java.io.ObjectStreamClass;
import java.io.ObjectStreamField;

public class ObjectSCTest {
    private String name = "";

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    private int age = 12;

    // 运行函数
    public static void main(String args[]) throws Exception {
        // 分别分析一个序列化类和非序列化的类
        ObjectStreamClass scNonSerial = ObjectStreamClass.lookupAny(ObjectSCTest.class);
        ObjectStreamClass scSerial = ObjectStreamClass.lookup(SerialPerson.class);
        // 打印类名
        System.out.println(scNonSerial.getName());
        System.out.println(scSerial.getName());
        // 打印所有信息，自动调用toString()
        System.out.println(scNonSerial);
        System.out.println(scSerial);
        // 返回字段描述
        ObjectStreamField[] fields = scSerial.getFields();
        for( ObjectStreamField field : fields){
            System.out.println(field);
        }
    }
}